package com.xy.config;

import com.xy.bean.Color;
import com.xy.bean.ColorFactory;
import com.xy.bean.Person;
import com.xy.bean.Red;
import com.xy.condition.LinuxCondition;
import com.xy.condition.MyBeanImport;
import com.xy.condition.MyImportSelector;
import com.xy.condition.WindowsConditional;
import com.xy.filter.MyTypeFilter;
import org.springframework.context.annotation.*;

import javax.swing.*;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/4/6 15:32
 * @description 配置类 代替 配置文件
 */


@Import({Color.class, Red.class, MyImportSelector.class, MyBeanImport.class})
@Conditional(WindowsConditional.class)
@Configuration
public class MainConfig2 {

    /**
     * @scope：
     *      1. prototype 多实例
     *      2. singleton 单实例
     *
     * @Lazy 懒加载
     *      单实例bean： 默认在容器启动时创建对象
     *      懒加载， 容器启动时不创建对象，第一次获取对象是创建
     */
    //@Scope("prototype")
    @Lazy
    @Bean(value = "person")
    public Person person() {
        System.out.println("容器中添加了person....");
        return new Person("jack", 21);
    }

    /**
     * @Conditional 按照一定的条件判断，满足条件给容器中注册bean
     */
    @Conditional(WindowsConditional.class)
    @Bean("bill")
    public Person person01() {
        return new Person("Bill Gates",66);
    }

    //@Conditional()
    @Conditional(LinuxCondition.class)
    @Bean("linus")
    public Person person02() {
        return new Person("linus",52);
    }

    @Bean
    public ColorFactory colorFactory() {
        return new ColorFactory();
    }
}
